## GroundEnemyMove
class_name GroundEnemyMove
extends GroundEnemyBase


export var min_move_distance : float = 16
export var max_move_distance : float = 48


var _move_timer : Timer = create_timer()


#(override)
func enter():
	if get_data('move_forward'):
		var p = get_host().global_position
		var r_dist : float = rand_range(min_move_distance, max_move_distance)
		p.x += r_dist * [-1, 1][randi() % 2]
		
		var move_speed : float = WrapperHelper.get_property(owner).get_property("move_speed")
		var distance : float = abs(p.x - get_host().global_position.x)
		_move_timer.start(distance / move_speed)
		
		var direction = sign(p.x - get_host().global_position.x)
		change_direction(direction)


#(override)
func exit():
	set_data("move_forward", null)


#(override)
func state_process(_arg0):
	if has_wall() or is_no_way():
		change_direction()
	input_forward_move()
	
	if has_player():
		switch_to(GroundEnemyStateBlackboard.States.ATTACK)
		
	elif (_move_timer.time_left <= 0):
		if randf() > 0.3:
			switch_to(GroundEnemyStateBlackboard.States.IDLE)
		else:
			switch_to(GroundEnemyStateBlackboard.States.LOOK_AROUND)
	


